//
//  HYInfoTitleCell.m
//  HaiYue
//
//  Created by skyline on 2018/2/6.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYInfoTitleCell.h"
#import "HYAuthorView.h"
#import "HYInfoLabel.h"
@interface HYInfoTitleCell()
@property (nonatomic, strong) HYLabel *titleLBL;
@property (nonatomic, strong) HYAuthorView *authorView;
@end
@implementation HYInfoTitleCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.separatorInset = UIEdgeInsetsMake(0, SCREEN_WIDTH, 0, 0);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (HYLabel *)titleLBL
{
    if (!_titleLBL)
    {
        _titleLBL= [[HYLabel alloc] initWithText:@"" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:TitleFont weight:UIFontWeightBold]];
        _titleLBL.fixedWidth = SCREEN_WIDTH - 2 * GAP;
        [self addSubview:_titleLBL];
        [_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.top.equalTo(self).with.offset(GAP);
        }];
    }
    return _titleLBL;
}

- (HYAuthorView *)authorView
{
    if (!_authorView)
    {
        _authorView = [[HYAuthorView alloc] init];
        [self addSubview:_authorView];
        [_authorView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLBL.mas_bottom).with.offset(GAP);
            make.left.equalTo(self);
            make.size.mas_equalTo(self.authorView.bounds.size);
        }];
    }
    return _authorView;
}

- (void)setDict:(NSDictionary *)dict
{
    if (_dict != dict)
    {
        _dict = dict;
        self.titleLBL.text = [_dict valueForKey:@"title"];
        self.authorView.dict = _dict;
        [self updateBounds];
    }
}

- (void)updateBounds
{
    CGFloat height = _titleLBL.bounds.size.height + _authorView.bounds.size.height + GAP * 3;
    self.bounds = CGRectMake(0, 0, SCREEN_WIDTH, height);
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
